<?php

require_once(dirname(__FILE__) . '/appconf.php');

class FnbApi extends Site {

    function setup() {
        $this->run_modes('newproduct');
        $this->start_mode('newproduct');
        $this->selfurl = '/blog.php';
        parent::setup();
    }

    function cgiapp_prerun() {
        $this->Product = getModel('Model_Product');
        parent::cgiapp_prerun();
    }

	function action_newproduct(){
		$callback = $this->get_q('callback','');
		//$kvcobj = getCache('newproduct', array('expire' =>KVC_EXPIRE));
        //$invite_new_list = $kvcobj->get('invite_new_list');
        //if (!$invite_new_list) {
        $invite_new_list = $this->Product->get_new_invite_list();
        //    $kvcobj->set('invite_new_list', $invite_new_list);
        //}
		$retarr = array();
		foreach($invite_new_list as $k=>$v){
			$retarr[$k]['id'] = $v['id'];
			$retarr[$k]['name'] = $v['name'];
			$retarr[$k]['cname'] = $v['cname'];
			$retarr[$k]['brand'] = $v['brand'];
			$retarr[$k]['quota'] = $v['quota'];
			$retarr[$k]['apply_num'] = $v['apply_num'];
			$retarr[$k]['click'] = $v['click'];
			$retarr[$k]['likes'] = $v['likes'];
			$retarr[$k]['body'] = $v['body'];
			$retarr[$k]['remark'] = $v['remark'];
			$retarr[$k]['cover'] =  $this->param('URL').$v['cover'];
			$retarr[$k]['type_name'] = $v['type_name'];
			$retarr[$k]['member_type'] = $v['member_type'];
			$retarr[$k]['status'] = $v['status'];
			$retarr[$k]['apply_starttime'] = $v['apply_starttime'];
			$retarr[$k]['apply_endtime'] = $v['apply_endtime'];
			$retarr[$k]['report_starttime'] = $v['report_starttime'];
			$retarr[$k]['report_endtime'] = $v['report_endtime'];
			$retarr[$k]['price_trial'] = $v['price_trial'];
			$retarr[$k]['capacity_trial'] = $v['capacity_trial'];
			$retarr[$k]['url'] = 
				time() > strtotime($v['report_endtime']) ? 
				$this->param('URL').optimize_url('product', 'detail', 'mtype='.$v['member_type'].'&pid='. $v['id']) : 
				$this->param('URL').optimize_url('product', 'invite_inpage', 'mtype='.$v['member_type'].'&pid='. $v['id']);
			if(count($retarr)>=3)break;
		}
		$param=array(
			'data'=>$retarr,
			'callback' => $callback,
			);
		//print_r($param);
		$return_obj = getLibClass('DataReturn',$param);
		$return_obj->data_return();
	}
}

header("Content-type: text/html; charset=utf-8");
$webapp = new FnbApi();
$webapp->run();
?>